﻿using AnesSystem.Models;
using AnesSystem.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace AnesSystem.Controls
{
    /// <summary>
    /// DoctorCountCtrl.xaml 的交互逻辑
    /// </summary>
    public partial class DoctorCountCtrl : UserControl
    {
        public DoctorCountCtrl()
        {

            InitializeComponent();
            InitializeComponent();
            _xuanZeDataGrid.LoadingRow += _xuanZeDataGrid_LoadingRow;
            this.DataContext = DoctorCountCtrlViewModel.Instance;
            bis.Visibility = DoctorCountCtrlViewModel.Instance.DeleteIsVis;
            bisNum.Visibility = DoctorCountCtrlViewModel.Instance.DeleteIsVis;

        }

        private void _xuanZeDataGrid_LoadingRow(object sender, DataGridRowEventArgs e)
        {
            e.Row.Header = e.Row.GetIndex() + 1;
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Task.Factory.StartNew(delegate
                {
                    Dispatcher.Invoke(delegate
                    {
                        DoctorCountCtrlViewModel.Instance.Seach();
                        MainPageCommonViewModel.Instance.WaitCtrlVisibility = Visibility.Collapsed;
                    });
                    return;
                });
                MainPageCommonViewModel.Instance.WaitCtrlVisibility = Visibility.Visible;
            }
            catch (Exception ex)
            {
                Common.LogHelper.Error(this.GetType(), ex);
            }
        }

        private void _dgNoSchedule_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                BaseCountModel baseCountModel = _dgNoSchedule.SelectedItem as BaseCountModel;
                DoctorCountCtrlViewModel.Instance.UpdateDisPatientLinkModelList(baseCountModel);
            }
            catch (Exception ex)
            {
                Common.LogHelper.Error("NoSecheduledListCtrl", ex);
            }
        }

        private void dcexcel_Click(object sender, RoutedEventArgs e)
        {
            DoctorCountCtrlViewModel.Instance.Excel();
        }

        private void _abc_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            PatientLinkModel model = _xuanZeDataGrid.SelectedValue as PatientLinkModel;
            if (model == null)
            {
                MessageBoxCommon.ShowDialog("请选择一个病人!", MessageBoxCommon.OK);
                return;
            }
            DataManager.Instance.CurrentPatientLink = model;
            MainPageCommonViewModel.Instance.NavigateTo("AnesRecordCtrl", false);
        }
    }
}
